/*
 * Copyright (c) 2010-2013 Ruben Chakhmakhchyan. All rights reserved.
 * 
 * This file contains Original Code and/or Modifications of Original Code
 * as defined in and that are subject to the Eclipse Public License
 * Version 1.0 (the 'License'). You may not use this file except in
 * compliance with the License. Please obtain a copy of the License at
 * http://opensource.org/licenses/EPL-1.0 and read it before using this file.
 */

#pragma once

#include "image_acquisition_model.h"
#include "image_site.h"
#include <stdlib.h>
#include "list.h"


class TestDriverModel : public ImageAcquisitionModel
{
public:

	TestDriverModel( ImageSite* imageSite, MessageListener* messageListener );
	virtual ~TestDriverModel();

	// ImageAcquisitionModel interface implementation
	virtual int getModelTypeId() const { return 2; }
	virtual char* getModelTypeName() const { return ( char* ) m_modelTypeName; }
	virtual void setIdentity( char* productName ) { }

	virtual bool getDevices();
	virtual ImagingDevice* getDevice( int index );
	virtual int getDeviceCount() { return m_devices.count(); }

	virtual bool getShowDeviceUI() const { return false; }
	virtual void setShowDeviceUI( bool value ) { }

	virtual int getDeviceIndex() const { return m_deviceIndex; }
	virtual void setDeviceIndex( int value ) { m_deviceIndex = value; }

	virtual const ImagingDevice& getCurrentDevice() const { return m_devices[ m_deviceIndex ]; }
	
	virtual ResultCode scan();

	virtual PixelType getPixelType() const { return m_pixelType; }
	virtual void setPixelType( PixelType value ) { m_pixelType = value; }
	virtual uint_t getResolution() const { return m_resolution; }
	virtual void setResolution( uint_t value ) { m_resolution = value; }
	virtual PaperSource getPaperSource() const { return PaperSource::Feeder; }
	virtual void setPaperSource( PaperSource value ) { }
	virtual bool getAutoBright() const { return m_autoBright; }
	virtual void setAutoBright( bool value ) { }
	virtual int getContrast() const { return m_contrast; }
	virtual void setContrast( int value ) { m_contrast = value; }
	virtual double getPageWidth() const { return 0; }
	virtual void setPageWidth( double value ) { }
	virtual double getPageHeight() const { return 0; }
	virtual void setPageHeight( double value ) { }
	virtual void setPageSize( double width, double height ) { }

	virtual bool getIsPaperSourceFixed() const;

	virtual bool getDuplex() const { return false; }
	virtual void setDuplex( bool value ) { }

	virtual int getOrientation() const { return m_orientation; }
	virtual void setOrientation( int value ) { m_orientation = value; }

	virtual bool getIsDeviceFeatureSupported( DeviceFeature deviceFeature ) const;
	virtual long initializeDevice() { return 0; }

	virtual void setParentWindow( void* handle ) { }

	virtual BaseCap* getCap( uint_t cap );

	virtual bool connect() { return ( m_connected = true ); }
	virtual void disconnect() { m_connected = false; }
	virtual bool getIsConnected() const { return m_connected; }

	virtual void deviceChange( bool state ) { }

private:

	void loadFromFile( char* filename );

private:

	byte_t* m_buffer;

	List<ImagingDevice> m_devices;

	uint_t m_deviceIndex;
	uint_t m_resolution;
	PixelType m_pixelType;
	long m_colorDepth;
	long m_dataType;
	long m_imageTypeIntent;
	bool m_autoBright;
	int m_contrast;
	int m_orientation;

	bool m_connected;

	static char m_modelTypeName[];

	ImageSite* m_pImageSite;
	MessageListener* m_messageListener;
};
